package CamEndzyx;

import com.github.sarxos.webcam.Webcam;

import java.awt.*;
import java.awt.image.BufferedImage;

//定义线程类
public class ThreadPixel extends Thread {
    public Graphics g;
    public boolean flag = true;  //控制线程的标记

    //初始化画笔对象
    public ThreadPixel(Graphics g) {
        this.g = g;
    }

    // 启动线程后自定执行的方法
    // run 方法执行完，该线程结束，线程一旦结束不能再次启动
    public void run() {
        System.out.println("启动线程.."+this.getName());

        // 启动摄像头，放在线程中启动
        Webcam webcam = Webcam.getDefault();
        webcam.open();

        while (flag) {
            // 获取摄像头拍到的数据
            BufferedImage bufferedImage = webcam.getImage();
            g.drawImage(bufferedImage, 50, 50,800,600, null);
        }
    }
}
